package com.tarena.lbs.attach.service.impl;

import com.tarena.lbs.attach.service.FileService;
import com.tarena.lbs.attach.service.QrCodeService;
import com.tarena.lbs.attach.util.QrCodeUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Base64;

@Service
public class QrCodeServiceImpl implements QrCodeService {

    @Autowired
    private FileService fileService;

    @Override
    public String generateQrCode(String content, int width, int height) {
        byte[] qrCodeImage = QrCodeUtil.generateQrCodeImage(content, width, height);
        // 将二维码图片保存为文件并返回访问URL
        try {
            // 这里简化处理，实际应用中可能需要将二维码图片保存到文件系统或MinIO
            return "data:image/png;base64," + Base64.getEncoder().encodeToString(qrCodeImage);
        } catch (Exception e) {
            throw new RuntimeException("生成二维码失败", e);
        }
    }
}
